package com.xieyong.mywebsite.mapper;

import com.xieyong.mywebsite.model.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface CategoryMapper {

    @Insert("INSERT INTO category (category_name, category_alias, create_id, create_time, update_time)" +
            " values (#{categoryName}, #{categoryAlias}, #{createId}, #{createTime}, #{updateTime}) ")
    void insert(Category category);

    List<Category> selectByCondition(Category category);

    @Select("select * from category where is_deleted = 0 and create_id = #{id}")
    List<Category> list(Integer id);

    @Select("SELECT * FROM category where is_deleted = 0 and id = #{id}")
    Category selectById(Integer id);

    @Update("UPDATE category set category_name = #{categoryName}, category_alias = #{categoryAlias}, update_time = #{updateTime} where id = #{id}")
    void update(Category category);

    @Update("UPDATE category set is_deleted = 1, deleted_id = #{operatorId}, deleted_time = #{deletedTime} where id = #{deleteId}")
    void delete(Integer deleteId,Integer operatorId, LocalDateTime deletedTime);
}
